﻿@model IEnumerable<SensitiveWord>
@{
    Layout = "_ControlPanel";
    var sensitiveWordTypes = ViewData.Get<IEnumerable<SensitiveWordType>>("sensitiveWordTypes", null);
    SensitiveWordService sensitiveWordServices = new SensitiveWordService();
    
}

<div class="tn-block">
    <div class="tnc-main">
        <div class="tnc-rightvar tn-open">
            <div class="tnc-settings-icon" plugin="ShortcutMenu">
                <a href="#"></a>
            </div>
            <div id="ManageUserRightMenu">
                <div class="tnc-settings">
                    @Html.Partial("_RightSensitiveWords")
                </div>
            </div>
        </div>
        <div class="tnc-ctn-center">
            <h1>
                <span>敏感词管理</span></h1>
            <div class="tnc-ctnright-list">
                 <div class="tn-cue-highlight tn-corner-all tn-message-box">
                    <ul>
                        <li><strong>提示</strong></li>
                        <li>1.可以同时添加多个敏感词,每行只允许有一个,敏感词与被替代字符之间用等号隔开,例如:法轮功=*。</li>
                        <li>2.可以通过直接导入的方式添加敏感词导入文件的格式与在程序手动中添加要求一致。</li>
                        <li>3.为不影响程序效率，请不要设置过多不需要的过滤内容。</li>
                    </ul>
                </div>
                <div class="tn-manager-search tn-helper-clearfix">
                    <div class="tnc-shortsearch-adminform">
                        @using (Html.BeginForm("ManageSensitiveWords", "ControlPanelSettings", FormMethod.Get))
                        {
                            <div class="tn-form-row">
                                <label class="tn-form-label">
                                    敏感词关键字：</label>
                                @Html.TextBox("keyword", Request.QueryString.Get<string>("keyword", string.Empty), new { maxlength = "32", @class = "tn-textbox tn-input-medium tn-border-gray" })
                            </div>
                            <div class="tn-form-row">
                                @Html.DropDownList("typeId", new SelectList(sensitiveWordTypes, "TypeId", "Name"), "请选择类别", new { @class = "tn-dropdownlist" })
                            </div>                
                            <div class="tn-form-row">
                                @Html.Button("搜索", ButtonTypes.Submit, HighlightStyles.Primary)
                            </div>      
                        }
                    </div>
                </div>
                <div class="tnc-content-manage">
                    <div class="tn-list-header">
                        <div class="tn-toolbar-area">
                            @Html.LinkButton("添加", SiteUrls.Instance()._AddSensitiveWord(), iconType: IconTypes.SmallAdd, htmlAttributes: new { plugin = "dialog" })
                            @Html.LinkButton("导出", SiteUrls.Instance()._OutputSensitiveWords(), iconType: IconTypes.Download)
                            @Html.LinkButton("导入", SiteUrls.Instance()._InputSensitiveWords(), iconType: IconTypes.Upload, htmlAttributes: new { plugin = "dialog" })
                            @Html.LinkButton("删除", SiteUrls.Instance().DeleteSensitiveWords(), iconType: IconTypes.SmallCross, htmlAttributes: new { id = "delete-sensitiveWords" })
                        </div>
                    </div>
                    @if (Model.Count() == 0)
                    {
                        <div class="tn-no-data">
                            暂无敏感词</div>
                    }
                    else
                    {
                        <form id="batchform" method="post">
                        <table class="tn-table-grid">
                            <tbody>
                                <tr class="tn-table-grid-header">
                                    <th class="tn-border-gray tn-border-bottom tn-width-check">
                                        <input id="select-all" type="checkbox" />
                                    </th>
                                    <th class="tn-border-gray tn-border-bottom tn-text-note">
                                        敏感词
                                    </th>
                                    <th class="tn-border-gray tn-border-bottom tn-text-note">
                                        级别
                                    </th>
                                    <th class="tn-border-gray tn-border-bottom tn-text-note">
                                        类别
                                    </th>
                                    <th class="tn-border-gray tn-border-bottom tn-text-note">
                                        操作
                                    </th>
                                </tr>
                                @foreach (var sensitiveWord in Model)
                                {
                                    <tr class="tn-table-grid-row" id="searched_@(sensitiveWord.Id)" >
                                        <td class="tn-border-gray tn-border-bottom tn-width-check">
                                            @Html.SipmleCheckBox("ids", sensitiveWord.Id, false, new { @class = "sensitiveWord-id", value = @sensitiveWord.Id })
                                        </td>
                                        <td class="tn-border-gray tn-border-bottom tn-width-category  tn-nowrap">
                                            @sensitiveWord.Word
                                        </td>
                                        <td class="tn-border-gray tn-border-bottom tn-width-category  tn-nowrap">
                                            @if (sensitiveWord.Replacement == "{Banned}")
                                            {@:禁用
                                            }
                                            else
                                            {
                                                <text>替换为：@sensitiveWord.Replacement</text>
                                             }
                                        </td>
                                        <td class="tn-border-gray tn-border-bottom tn-width-category  tn-nowrap">
                                            @if (sensitiveWordServices.GetSensitiveWordType(sensitiveWord.TypeId) != null)
                                            {
                                                @sensitiveWordServices.GetSensitiveWordType(sensitiveWord.TypeId).Name
                                            }
                                        </td>
                                        <td class="tn-border-gray tn-border-bottom tn-width-action2 tn-nowrap">
                                            @Html.Link("编辑", SiteUrls.Instance()._AddSensitiveWord(sensitiveWord.Id), "编辑", new { plugin = "dialog" })
                                            @Html.AjaxDeleteButton(new AjaxDeleteButton().SetConfirm("确定要删除吗？").SetText("删除").SetTooltip("删除敏感词").SetDeleteTarget("#searched_" + sensitiveWord.Id).SetUrl(SiteUrls.Instance().DeleteSensitiveWords(sensitiveWord.Id)).SetOnErrorCallBack("error").SetOnSuccessCallBack("success"))
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                        </form>                        
                    }
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" language="javascript">
    $(function () {
        removeChecked();
        //处理火狐下浏览器刷新后复选框仍然选中
        function removeChecked() {
            $(".sensitiveWord-id").each(function () {
                if ($(this).attr("checked")) {
                    $(this).removeAttr("checked");
                }
            });
            $("#select-all").removeAttr("checked");
        }



        // 全选 全不选
        $("#select-all").click(function () {
            //设置下面复选框的状态
            if ($(this).attr("checked")) {
                $(".sensitiveWord-id").each(function () {
                    $(this).attr("checked", true);
                });
            } else {
                $(".sensitiveWord-id").each(function () {
                    $(this).removeAttr("checked");
                });
            }
        });



        //点批量删除
        $("#delete-sensitiveWords").click(function (e) {
            e.preventDefault();
            if (!$("form input[name='ids']:checked").length) {
                alert("请至少选择一个敏感词！");
                return;
            }

            var url = $(this).attr("href");
            art.dialog.confirm('您确认要删除吗？', function () {
                $("#batchform").ajaxSubmit({
                    success: function (data) {
                        window.location.reload(true);
                    },
                    url: url,
                    error: function (XMLResponse) {
                        //alert(XMLResponse.responseText);   
                        alert('操作失败！');
                    }
                });
            });
        });



        $(".tn-table-grid-row").hover(
            function () {
                $(this).addClass("tn-bg-gray");
            },
            function () {
                $(this).removeClass("tn-bg-gray");
            }
        );

    });
    function error() {
        art.dialog.tips("删除失败！", 2, -1);
    }

    function success() {
        art.dialog.tips("删除成功！", 2, 1);
    }
</script>
